<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Express extends Stourweb_Controller{


    public function before()
    {
        parent::before();
    }

    //获取目的地
    public function action_ajax_get_area()
    {
        $pid = intval($_POST['pid']);
        $list = DB::select()->from('express_destination')->where('pid','=',$pid)->execute()->as_array();
        echo json_encode($list);
    }

    //返回js格式的省份城市数组
    public function action_mobile_city_js()
    {
        $list = DB::select()->from('express_destination')->where('pid','=',0)->execute()->as_array();
        $area_arr = array();
        foreach($list as $province)
        {
            $p_row = array('text'=>$province['cityname']);
            $city_list = DB::select()->from('express_destination')->where('pid','=',$province['id'])->execute()->as_array();
            $children = array();
            foreach($city_list as $city)
            {
                $children[] = array('text'=>$city['cityname']);
            }
            if(!empty($children))
            {
                $p_row['children'] = $children;
            }
            $area_arr[] = $p_row;
        }
        $js_str = " var cityData3=".json_encode($area_arr);
        echo $js_str;
    }
}